package com.learn.project2.controller.admin;

import com.learn.project2.config.customException.NoChooseCategoryL1Exception;
import com.learn.project2.model.bo.admin.category.CategoryCreateBO;
import com.learn.project2.model.bo.admin.category.CategoryDeleteBO;
import com.learn.project2.model.bo.admin.category.CategoryUpdateBO;
import com.learn.project2.model.vo.admin.category.CategoryCreateVO;
import com.learn.project2.model.vo.admin.category.CategoryListVO;
import com.learn.project2.model.vo.admin.category.Categoryl1VO;
import com.learn.project2.service.admin.category.CategoryService;
import com.learn.project2.utils.Result;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description:
 * @author 亓永杰
 * @date 2022-01-08 17:09
 * @version 1.0
 */
@RestController
@RequestMapping("admin/category")
public class CategoryController {

    @Autowired
    CategoryService categoryService;
/**
 * @description: 获取商品类目
 * @param:
 * @return:
 * @author 亓永杰
 * @date: 2022-01-08 22:37
 */
    @RequiresPermissions("admin:category:list")
    @RequestMapping("list")
    public Result list(){
        CategoryListVO categoryListVO = categoryService.listCategory();
        return Result.ok(categoryListVO);
    }
/**
 * @description: 获取一级类目
 * @param:
 * @return:
 * @author 亓永杰
 * @date: 2022-01-08 22:37
 */
    @RequestMapping("l1")
    public Result l1(){
        Categoryl1VO categoryl1VO = categoryService.getL1();
        return Result.ok(categoryl1VO);
    }
/**
 * @description: 创建新类目
 * @param:
 * @return:
 * @author 亓永杰
 * @date: 2022-01-08 22:37
 */
    @RequestMapping("create")
    @RequiresPermissions("admin:category:create")
    public Result create(@RequestBody CategoryCreateBO categoryCreateBO) throws NoChooseCategoryL1Exception {
        CategoryCreateVO categoryCreateVO = categoryService.insertCategory(categoryCreateBO);
        return Result.ok(categoryCreateVO);
    }
    /**
     * @description: 编辑类目
     * @param:
     * @return:
     * @author 亓永杰
     * @date: 2022-01-08 22:37
     */
    @RequestMapping("update")
    @RequiresPermissions("admin:category:update")
    public Result update(@RequestBody CategoryUpdateBO categoryUpdateBO){
        categoryService.updateCategory(categoryUpdateBO);
        return Result.ok();
    }
    /**
     * @description: 删除类目
     * @param:
     * @return:
     * @author 亓永杰
     * @date: 2022-01-08 22:37
     */
    @RequestMapping("delete")
    @RequiresPermissions("admin:category:delete")
    public Result delete(@RequestBody CategoryDeleteBO categoryDeleteBO){
        categoryService.deleteCategory(categoryDeleteBO);
        return Result.ok();
    }

}
